package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.MerchantBannerService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.MerchantBannerDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author chenqiwen
 * @CreateDate: 2022-08-18-17-55
 * @Description:
 */
@RestController
@RequestMapping("/api/merchantBanner")
public class MerchantBannerController extends UserInfoController {

    @Autowired
    private MerchantBannerService merchantBannerService;

    /**
     * 保存修改广告
     *
     * @param merchantBannerDto
     * @param request
     * @return
     */
    @PostMapping("/save")
    public ServerResponse save(@RequestBody MerchantBannerDto merchantBannerDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        merchantBannerDto.setUserInfo(userInfo);
        return merchantBannerService.save(merchantBannerDto);
    }

    /**
     * 同步
     */
    @PostMapping("/findSendAgreement")
    public ServerResponse findSendAgreement(@RequestBody MerchantBannerDto merchantBannerDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        merchantBannerDto.setUserInfo(userInfo);
        return merchantBannerService.findSendAgreement(merchantBannerDto);
    }

    /**
     * 删除广告图
     *
     * @param merchantBannerDto
     * @param request
     * @return
     */
    @PostMapping("/deleteMerchantBanner")
    public ServerResponse deleteMerchantBanner(@RequestBody MerchantBannerDto merchantBannerDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        merchantBannerDto.setUserInfo(userInfo);
        return merchantBannerService.deleteMerchantBanner(merchantBannerDto);
    }


    /**
     * 根据登录用户权限和场地ID查广告
     *
     * @param merchantBannerDto
     * @param request
     * @return
     */
    @PostMapping("/findAllMerchantBannerByMerchantStoreId")
    public ServerResponse findAllMerchantBannerByMerchantStoreId(@RequestBody MerchantBannerDto merchantBannerDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        merchantBannerDto.setUserInfo(userInfo);
        return merchantBannerService.findAllMerchantBannerByMerchantStoreId(merchantBannerDto);
    }

    @GetMapping("/findMerchantBannerByUserId")
    public ServerResponse findMerchantBannerByUserId(MerchantBannerDto merchantBannerDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        merchantBannerDto.setUserInfo(userInfo);
        return merchantBannerService.findMerchantBannerByUserId(merchantBannerDto);
    }
}

